


import asyncio
import time

 


from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
# 缓存管理示例
cache_opts = {
    'cache.type': 'file',
    'cache.data_dir': './cache_data',
    'cache.expire': 3600
}
cache = CacheManager(**parse_cache_config_options(cache_opts))

@cache.cache('square_cache', expire=300)
def square(x):
    print("仅首次调用会执行 square...")  # 仅首次调用会执行
    return x * x


square(1)
square(1)


'''
async def main():
   print("K")

uvloop.run(main())


async def say_after(delay, what):
    await asyncio.sleep(delay)
    print(what)

async def main():
    print(f"started at {time.strftime('%X')}")

    await say_after(1, 'hello')
    await say_after(2, 'world')

    print(f"finished at {time.strftime('%X')}")

asyncio.run(main())





import asyncio

async def main():
    await asyncio.sleep(1)
    print('hello')

asyncio.run(main())

'''